<?php
namespace App\Adshopuser\Models;
use Common\BaseModel;
use Common\Common;

class BShopOperationLog extends BaseModel
{
    public $res;
    public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('b_shop_operation_log');
    }

    public function get_list($params){
        $page = intval($params['page']);
        $size = intval($params['limit']);
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $get_list['items'] = $this->find(array(
                "conditions"=>"shop_id={$params['shop_id']}",
                "offset"=>$page,
                "limit"=>$size,
                "order"=>"created_at desc"
            )
        )->toarray();
        $get_list['total'] = $this->count();
        return $get_list;
    }


    public function params_save($params=[],$admin_user=[]){
        $this->shop_id = $admin_user['id'];
        $this->path = $params['_url'];
        $this->method = isset($_SERVER['REQUEST_METHOD']) && !empty($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
        $this->ip = Common::get_real_ip();
        $this->input = json_encode($params);
        $this->created_at = date('Y-m-d H:i:s');
        $this->updated_at = date('Y-m-d H:i:s');
        $this->save();
    }


}
